<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title></title>
<link href="houtai/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="houtai/js/main.js"></script>
<script type="text/javascript">
	function fuclick(f,fi){
	
		var arr=document.getElementsByName(fi);
			
			   for(var i=0;i<arr.length;i++){
			   			arr[i].checked=f.checked;
				}
	
	}

	function ziclick(z,fi){
		var ar=document.getElementsByName(fi);
			
				var flag=false;
				for(var i=1;i<ar.length;i++){
				 if(ar[i].checked){
				 	flag=true;
				    }
				}
				ar[0].checked=flag;
		
	
	}


var xmlhttp;
function ckrolname(){
	
	var rolname=document.getElementById("rolName").value;
	var id=document.getElementById("rolid").value;
	if(rolname==""){
		document.getElementById("spnrolname").innerHTML="角色名不能为空";
		document.getElementById("spnrolname").style.color="red";
		return false;
	}
	document.getElementById("spnrolname").innerHTML="";
	xmlhttp=new XMLHttpRequest();
	xmlhttp.onreadystatechange=huirolname;
	xmlhttp.open("get", "RoleServlet?param=ajaxrolename&id="+id+"&rolname="+rolname+"&time="+new Date().getTime(), true);
	xmlhttp.send(null);
	
}
function huirolname(){
	if(xmlhttp.readyState==4&&xmlhttp.status==200){
		var txt=xmlhttp.responseText;
		document.getElementById("spnrolname").innerHTML=txt;
		if(txt=="√"){
			document.getElementById("spnrolname").style.color="green";

		}else{
		document.getElementById("spnrolname").style.color="red";
		}
	}
}


function ckrname(){
	var rolname=document.getElementById("rolName").value;
	if(rolname==""){
		document.getElementById("spnrolname").innerHTML="角色名不能为空";
		document.getElementById("spnrolname").style.color="red";
		return false;
	}
	document.getElementById("spnrolname").innerHTML="";
	return true;
}

function ckspan(){
	var spn=document.getElementById("spnrolname").innerHTML;
	if(spn=="角色名已存在"){
		alert("角色名已存在");
		return false;
	}
	return true;
}

function ckremark(){
	if(document.getElementById("rolremark").value==""){
		document.getElementById("s1").innerHTML="备注不能为空";
		document.getElementById("s1").style.color="red";
		return false;
	}
	document.getElementById("s1").innerHTML="";
	return true;
}

function chesub(){

	if(ckspan()&&ckrname()&&ckremark()){
		if(confirm("确定提交吗?")){
			document.getElementById("form6").submit();
			return true;
		}
	}else{
		return false;
	}
}
</script>
</head>
<body>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td style="height:25px; background-color:#f3f3f3; font-weight:bold" valign="top">&nbsp;&nbsp;&nbsp;&nbsp;当前位置： 
    <img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;soda创业教育平台&nbsp;&nbsp;
    <img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;后台管理&nbsp;&nbsp;
    <img src="houtai/images/arrow.gif" align="absmiddle">&nbsp;&nbsp;角色管理
    </td>
  </tr>
  <tr>
    <td style="height:34px; background-image:url(houtai/images/main_header.gif); border-bottom:1px solid #cfd8e0; padding:0px">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="20" height="34"><img src="houtai/images/main_headerL.gif" width="20" height="34"></td>
          <td style="color:#90c8e8;"><img src="houtai/images/icon_card.gif" width="16" height="16" align="absmiddle">&nbsp;&nbsp;<strong>修改角色信息</strong></td>
          <td align="right" class="white" style="padding-right:20px">
          <a  class="barBtn" onClick="javascript:history.go(-1);"><img src="houtai/images/btn_left.gif" align="absmiddle"> 后退</a>
          <a  class="barBtn" onClick="javascript:history.go(+1);"><img src="houtai/images/btn_right.gif" align="absmiddle"> 前进</a>
          <a href="<%=request.getContextPath() %>/RoleServlet?param=editRole&id=${role.rolId }" class="barBtn"><img src="houtai/images/btn_refresh.gif" align="absmiddle"> 刷新</a>
          </td>
        </tr>
    </table></td>
    
  </tr>
  <tr>
    <td height="100%" valign="top">
    <div style="moz-overflow:auto;overflow:auto;height:500px; width:100%">
    <form id="form6" action="<%=request.getContextPath() %>/RoleServlet?param=saveRoleInfo" method="post">
      <table width="100%" border="0" cellpadding="3" cellspacing="1" class="table1">
        <TR>
        <input type="hidden" name="rolid" id="rolid" value="${role.rolId }" >
          <th width="20%" align="center">角色名</th>
          <TD class="BGCgray"><input type="text" name="rolName" id="rolName" onblur="ckrolname()" value="${role.rolName }"/><span onclick="ckspan()" id="spnrolname"></span></TD>
        </TR>
       <TR>
          <th align="center">对应菜单</th>
          <TD class="BGCgray">
			<ul>
			<c:forEach items="${requestScope.fmenus }" var="fm">
			<c:if test="${fm.fmeDelete==1 }" >
            	<li>
            	<input type="checkbox" name="fu${fm.fmeId }" value="${fm.fmeId }" onclick="fuclick(this,'fu${fm.fmeId}')"
            	<c:forEach items="${requestScope.role.fmenus }" var="m">
            	<c:if test="${m.fmeName==fm.fmeName }">  checked="checked" </c:if>
            	</c:forEach>  
            	
            	 />${fm.fmeName }
            	
                	<ul>
                	<c:forEach items="${fm.menus }"  var="menu">
                	<c:if test="${menu.menDelete==1}">
                   	<li><input type="checkbox"  name="fu${fm.fmeId }" value="${menu.menId}" onclick="ziclick(this,'fu${fm.fmeId}')"; 
                   	<c:forEach items="${requestScope.role.menus }" var="me"> 
                   	    <c:if test="${me.menName==menu.menName }">checked="checked" </c:if>
                   	</c:forEach>
                   	/>${menu.menName }</li>
                   	</c:if>
                   	</c:forEach>
                    </ul>
                </li>
                </c:if>
            </c:forEach>
            </ul>
          </TD>
        </TR>
         <TR>
          <th align="center">启用状态</th>
          <TD class="BGCgray">
          <input type="radio" name="rolState" value="1" ${requestScope.role.rolState==1?"checked='checked'":"" }/>启用
          <input type="radio" name="rolState" value="0" ${requestScope.role.rolState==0?"checked='checked'":"" }/>禁用
          </TD>
        </TR>
        <TR>
          <th align="center"><span class="BGCgray">备注</span></th>
          <TD class="BGCgray">
          	<textarea name="rolRemark" id="rolremark" onblur="ckremark()">${requestScope.role.rolRemark }
            </textarea><span id="s1"></span>
          </TD>
        </TR>
      </table>
        </form>
      <div style="width:100%; text-align:center; padding:5px">
        <BUTTON style="HEIGHT:25px" onclick="return chesub();"><img src="houtai/images/btn_edit.gif" width="16" height="16" align="absmiddle"> 修改</BUTTON><BUTTON style="HEIGHT:25px" onClick="history.go(-1);"><img src="houtai/images/btn_back.gif" width="16" height="16" align="absmiddle"> 返回</BUTTON>
      </div>
    </div>
  
  </td>
  </tr>
</table>

</body>
</html>